package com.qf.xiangqin.servlet;

import com.qf.xiangqin.dao.UserDao;
import com.qf.xiangqin.entity.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/api/user/register")
public class UserRegisterServlet extends HttpServlet {
    private UserDao dao=new UserDao();
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        User user = new User(req.getParameter("username"),req.getParameter("password"),req.getParameter("phone"));
        if (dao.selectByName(user.getUsername())==null){
            int r = dao.add(user);
            if (r>0){
                resp.getWriter().println(200);
            }else{
                resp.getWriter().println(400);
            }
        }else{
            resp.getWriter().println(300);
        }
    }
}
